package com.hitqz.robot.biz.controller;

import cn.hutool.core.bean.BeanUtil;
import com.hitqz.robot.api.business.model.vo.robot.RobotConfigVo;
import com.hitqz.robot.api.common.entity.RobotConfig;
import com.hitqz.robot.biz.service.RobotConfigService;
import com.hitqz.robot.common.core.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.net.UnknownHostException;

/**
 * @author xupkun
 * @date 2024/8/1
 */
@RestController
@RequestMapping(value = "robotConfig")
@Tag(name = "机器人配置数据")
@AllArgsConstructor
public class RobotConfigController {

    private final RobotConfigService robotConfigService;

    @GetMapping(value = "")
    @Operation(summary = "获取当前机器人配置")
    public R<RobotConfigVo> getConfig() throws UnknownHostException {
        RobotConfig robotConfig = robotConfigService.getOneEnable();
        RobotConfigVo robotConfigVo = new RobotConfigVo();
        BeanUtil.copyProperties(robotConfig, robotConfigVo, false);
        return R.ok(robotConfigVo);
    }

    @PostMapping
    @Operation(summary = "更新机器人配置")
    public R update(@RequestBody RobotConfigVo robotConfigVo) {
        RobotConfig robotConfig = robotConfigService.getById(robotConfigVo.getId());
        BeanUtil.copyProperties(robotConfigVo, robotConfig);
        robotConfigService.updateById(robotConfig);
        return R.ok();
    }


}
